(function() {
    'use strict';

    /**
     * @ngdoc function
     * @name webApp.controller:AttachCtrl
     * @description
     * # AttachCtrl
     * Controller of the webApp
     */
    angular.module('webApp')

        .controller('AttachCtrl', AttachCtrl);

    AttachCtrl.$inject = ['$scope', 'dataService', '$rootScope', '$timeout', '$location', 'helper', '$document', '$filter', 'sessionService'];


    function AttachCtrl($scope, dataService, $rootScope, $timeout, $location, helper, $document, $filter, sessionService) {


        //初始方法
        $scope.listAction = function() {
            if($scope.categoryId)
            {
                var categoryId = $scope.categoryId;
            }
            else
            {
                var categoryId = 0;
            }
            $scope.getlist(1,categoryId);
        }

        //获取列表
        $scope.getlist = function(pageNo,categoryId) {

            $scope.itemsTotal = 0;
            $scope.pageSize = 5;
            var query = {
                page_no: pageNo ? pageNo : "1",
                page_size: $scope.pageSize,
            };
            if(categoryId)
            {
                query.query = {categoryId:categoryId};
            }
            return dataService.attachGet(query).then(function(list) {
                $scope.attachs = list.attachment;
                $scope.itemsTotal = list.total_count;
            });
        }



        $scope.delete = function(uid,path) {
            if (uid) {
                helper.myConfirm('确认删除吗？', function() {
                    var query = { uuid: uid };
                    if(path.substr(0,22) == "https://img.dhfapp.com")
                    {
                        var delUrl = "/rest/v1/attach/delete";
                    }
                    else
                    {
                        var delUrl = "/rest/v1/tcos/delete";
                    }
                    dataService.attachDelete(query,delUrl).then(function(da) {
                        helper.myAlert("success", null, null, function() {
                            $scope.getlist(1);
                        });
                    });
                });

            }
        }


    }
})();